package com.voiceqsologger.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.voiceqsologger.entity.QsoLog;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 通联日志查询接口
 */
@RestController
@RequestMapping("/api/qso")
public class QsoLogController {

    @GetMapping("/list")
    public IPage<QsoLog> list(@RequestParam(defaultValue = "1") long page,
                              @RequestParam(defaultValue = "20") long size,
                              @RequestParam(required = false) String callsign) {
        return Db.lambdaQuery(QsoLog.class)
                .like(callsign != null && !callsign.isEmpty(), QsoLog::getCallsign, callsign)
                .orderByDesc(QsoLog::getCreatedAt)
                .page(new Page<>(page, size));
    }
}


